<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui"
	xmlns:c="http://java.sun.com/jsp/jstl/core" template="../index.xhtml">

	<h:head>
		<f:facet name="first">
			<meta content='text/html; charset=UTF-8' http-equiv="Content-Type" />
			<title>Sistema UTI Neonatal</title>
		</f:facet>
	</h:head>

	<ui:define name="content">

		<p:accordionPanel id="accGerenciarIntervencoes" activeIndex="0"
			multiple="true">

			<p:tab title="Gerenciar Intervencoes">

				<h:form id="formTableIntervencoes">

					<p:growl id="messages" showDetail="true" />

					<p:dataTable id="tableIntervencoes" var="intervencao"
						value="#{intervencaoController.intervencaoModel}" paginator="true" rows="5"
						selection="#{intervencaoController.intervencao}" selectionMode="single"
						paginatorPosition="bottom" widgetVar="intervencaoTable" emptyMessage="Nenhum registro encontrado!">

						<p:ajax event="rowSelect"
							update=":accGerenciarIntervencoes:formDialogIntervencao:crudIntervencao"
							oncomplete="dialogGerIntervencao.show()" />

						<f:facet name="header">
							<h:outputText value="Pesquisar: "
								style="margin-left:4px;margin-top:4px;float:left;position:relative" />
							<p:inputText id="globalFilter"
								style="margin-left:3px;float:left;position:relative;width:150px" value="#{intervencaoController.intervencaoPesq.descricao}" />
							<p:commandButton id="botaoPesquisar" icon="ui-icon-search"
									update=":accGerenciarIntervencoes:formTableIntervencoes:tableIntervencoes"
									oncomplete="dialogGerIntervencao.hide();"
									actionListener="#{intervencaoController.pesquisarIntervencao}"
								style="margin-left:4px;margin-top:2px;width:20px;height:20px;float:left;position:relative"></p:commandButton>
						</f:facet>

						<p:column id="identificadorColumn" headerText="Identificador" style="width: 50%">
							<h:outputText value="#{intervencao.id}" />
						</p:column>

						<p:column id="descricaoColumn" headerText="Descrição" style="width: 50%">
							<h:outputText value="#{intervencao.descricao}" />
						</p:column>
						
						<p:column id="descricaoDiagColumn" headerText="Diagnósticos Associados" style="width: 50%">

							
														
						</p:column>
						
						

					</p:dataTable>

				</h:form>

				<p:dialog header="Gerencia de Intervencao" widgetVar="dialogGerIntervencao"
					resizable="false" showEffect="slide" width="500">

					<h:form id="formDialogIntervencao" prependId="false">

						<h:panelGrid id="crudIntervencao" columns="2" style="margin-top:10px">

							<f:facet name="header">
								<p:messages />
							</f:facet>

							<h:outputLabel for="descricao" value="Descrição:"
								style="margin-top:40px" />
							<h:inputText id="descricao"
								value="#{intervencaoController.intervencao.descricao}" required="true"
							requiredMessage="Descrição é campo obrigatório! Favor preencher."/>
								
							<h:outputLabel for="diagnosticoAlterar" value="Sintoma:"
								style="margin-top:40px" /> 

							<p:selectManyMenu id="diagnosticoAlterar" value="#{intervencaoController.diagnosticosSelecionados}"
								converter="IndexedConverter" style="height:100px; width: 165px;">
								<f:selectItems value="#{intervencaoController.listaDiagnosticos}" var="diagnostico"
									itemLabel="#{diagnostico.descricao}" itemValue="#{diagnostico}" />
							</p:selectManyMenu>
							<br />


							<div style="margin-top: 20px"></div>
							<f:facet name="footer">
								<p:commandButton
									update=":accGerenciarIntervencoes:formTableIntervencoes:tableIntervencoes :accGerenciarIntervencoes:formTableIntervencoes:messages"
									oncomplete="dialogGerIntervencao.hide();"
									actionListener="#{intervencaoController.alterarIntervencao}"
									value="Alterar Intervencao" />
								<p:commandButton value="Remover Intervencao"
									update=":accGerenciarIntervencoes:formRemover"
									oncomplete="remover.show()" />
							</f:facet>

						</h:panelGrid>

					</h:form>

				</p:dialog>

				<p:dialog widgetVar="remover" header="Remover Intervencao" width="500"
					resizable="false" showEffect="slide">

					<h:form id="formRemover">

						<h:outputText
							value="Tem certeza que quer remover: #{intervencaoController.intervencao.descricao} ?" />

						<h:panelGrid columns="2" style="margin-top:20px">

							<p:commandButton value="Sim"
								actionListener="#{intervencaoController.excluirIntervencao}"
								update=":accGerenciarIntervencoes:formTableIntervencoes:tableIntervencoes :accGerenciarIntervencoes:formTableIntervencoes:messages"
								oncomplete="dialogGerIntervencao.hide(), remover.hide()" />
							<p:commandButton value="Não" onclick="remover.hide()" />

						</h:panelGrid>

					</h:form>

				</p:dialog>

			</p:tab>

			<p:tab id="tabCriarIntervencao" title="Criar Intervencao">

				<h:form id="formCriaIntervencao" prependId="false">

					<h:panelGrid id="criaIntervencao" columns="3" style="margin-top:20px">

						<h:outputLabel for="descricao" value="Descrição:" />

						<p:inputText id="descricaoCriar"
							value="#{intervencaoController.novoIntervencao.descricao}" required="true"
							requiredMessage="Descrição é campo obrigatório! Favor preencher." />
						<br />

						<h:outputLabel for="diagnosticoAdicionar" value="Sintomas:"
								style="margin-top:40px" /> 

						<p:selectManyMenu id="diagnosticoAdicionar" value="#{intervencaoController.diagnosticosSelecionados}"
							converter="IndexedConverter" style="height:100px; width: 165px;">
							<f:selectItems value="#{intervencaoController.listaDiagnosticos}" var="diagnostico"
								itemLabel="#{diagnostico.descricao}" itemValue="#{diagnostico}" />
						</p:selectManyMenu>
						
						<br />

						<f:facet name="footer">
							<p:commandButton
								update=":accGerenciarIntervencoes:formTableIntervencoes:tableIntervencoes :accGerenciarIntervencoes:formCriaIntervencao:criaIntervencao :accGerenciarIntervencoes:formTableIntervencoes:messages"
								oncomplete="dialogGerIntervencao.hide();"
								actionListener="#{intervencaoController.adicionarIntervencao}"
								value="Criar Intervencao" style="margin-top:20px" />
						</f:facet>

					</h:panelGrid>

				</h:form>

			</p:tab>

		</p:accordionPanel>

	</ui:define>
</ui:composition>